﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Profari_Heldur_Utan_Um_Prof
{
    public partial class IntroductionTextTask : Form
    {
        public static string introTextTask;
        private static SqlConnection con = new SqlConnection("Data Source=JANA-PC\\SQLEXPRESS;Initial Catalog=dto1;Integrated Security=True " +
            "Initial Catalog=TestDB;Integrated Security=True");
        private static DataTable dt = new DataTable();
        private static SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM testProject2", con);

        public IntroductionTextTask()
        {
            InitializeComponent(); 
            ritxtIntroTextTask.Text = introTextTask;
            this.StartPosition = FormStartPosition.CenterScreen;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            //If user wants to quit the project he is moved to the first window
            DialogResult cancelProject = MessageBox.Show("Are you sure you want to stop making new project?", "Quit", MessageBoxButtons.YesNo);
            if (cancelProject == DialogResult.Yes)
            {
                System.Threading.Thread testerInterface = new System.Threading.Thread(new System.Threading.ThreadStart(OpenTesterInterface));
                testerInterface.SetApartmentState(System.Threading.ApartmentState.STA);
                testerInterface.Start();
                this.Close();
            }
        }        
        
        private void btnBack_Click(object sender, EventArgs e)
        {
            /*if (CheckBoxes.chkIntroTaskValue.Equals(1))
            {
                introTextTask = ritxtIntroTextTask.Text;
                System.Threading.Thread introTextSession = new System.Threading.Thread(new System.Threading.ThreadStart(OpenIntroductionTextSession));
                introTextSession.SetApartmentState(System.Threading.ApartmentState.STA);
                introTextSession.Start();
                this.Close();
            }
            else
            {*/
                introTextTask = ritxtIntroTextTask.Text;
                System.Threading.Thread createTask = new System.Threading.Thread(new System.Threading.ThreadStart(OpenCreateTask));
                createTask.SetApartmentState(System.Threading.ApartmentState.STA);
                createTask.Start();
                this.Close();
            //}
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            if (ritxtIntroTextTask.Text == "")
            {
                MessageBox.Show("Please put in some text");
            }
 /*           else if (CheckBoxes.chkInfoUserAfterValue.Equals(1) && CheckBoxes.radQuestionnaireValue.Equals(16))
            {
                introTextTask = ritxtIntroTextTask.Text;
                System.Threading.Thread createQuestionnaire = new System.Threading.Thread(new System.Threading.ThreadStart(OpenCreateQuestionnaire));
                createQuestionnaire.SetApartmentState(System.Threading.ApartmentState.STA);
                createQuestionnaire.Start();
                this.Close();
            }
            else if (CheckBoxes.chkInfoUserAfterValue.Equals(1) && CheckBoxes.radCheckboxesValue.Equals(16))
            {
                introTextTask = ritxtIntroTextTask.Text;
                System.Threading.Thread createCheckboxesQuestion = new System.Threading.Thread(new System.Threading.ThreadStart(OpenCreateCheckBoxesQuestion));
                createCheckboxesQuestion.SetApartmentState(System.Threading.ApartmentState.STA);
                createCheckboxesQuestion.Start();
                this.Close();
            }
            else if (CheckBoxes.chkInfoUserAfterValue.Equals(1) && CheckBoxes.radEssayValue.Equals(16))
            {
                introTextTask = ritxtIntroTextTask.Text;
                System.Threading.Thread createEssay = new System.Threading.Thread(new System.Threading.ThreadStart(OpenCreateEssay));
                createEssay.SetApartmentState(System.Threading.ApartmentState.STA);
                createEssay.Start();
                this.Close();
            }
            else if (CheckBoxes.chkInfoUserAfterValue.Equals(1) && CheckBoxes.radSurveyValue.Equals(16))
            {
                introTextTask = ritxtIntroTextTask.Text;
                System.Threading.Thread createSurvey = new System.Threading.Thread(new System.Threading.ThreadStart(OpenCreateSurvey));
                createSurvey.SetApartmentState(System.Threading.ApartmentState.STA);
                createSurvey.Start();
                this.Close();
            }*/
            else
            {
                introTextTask = ritxtIntroTextTask.Text;
                System.Threading.Thread createTask = new System.Threading.Thread(new System.Threading.ThreadStart(OpenCreateTask));
                createTask.SetApartmentState(System.Threading.ApartmentState.STA);
                createTask.Start();
                this.Close();
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
             /*
             * ritxtIntro = ritxtIntroTextSession.Text;
             *con.Open();
             *SqlCommand cmd = new SqlCommand("Insert INTO TAFLA(nafn á  Introduction textanum í töflunni)" + "VALUES(@ritxtIntro)", con);
             int restul = cmd.ExecuteNonQuery();
             * if(result > 0)
             * {
             *      MessageBox.Show("Introduction text has been saved");
             * }
             * con.Close();
             */
        }

        //The Open forms functions makes it able to move between forms and close the first form when the second one is opened
        #region OpenForms

        public static void OpenCheckBoxes()
        {
            Application.Run(new CheckBoxes());
        }

        public void OpenTesterInterface()
        {
            Application.Run(new TesterInterface());
        }

        public void OpenCreateTask()
        {
            Application.Run(new CreateTask());
        }

        public void OpenIntroductionTextSession()
        {
            Application.Run(new IntroductionText());
        }

        public void OpenCreateQuestionnaire()
        {
            Application.Run(new CreateQuestionnaire());
        }
        
        public void OpenCreateCheckBoxesQuestion()
        {
            Application.Run(new CreateCheckboxesQuestion());
        }
        
        public void OpenCreateEssay()
        {
            Application.Run(new CreateEssay());
        }
        
        public void OpenCreateSurvey()
        {
            Application.Run(new CreateSurvey()); 
        }
        #endregion

    }
}
